home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / plugin / weapon / laser.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-26  |  5.2 KB  |  265 lines

  1. #include "..\..\lib\Fly3D.h"
  2. #include "weapon.h"
  3.  
  4. int laser::step(int dt)
  5. {
  6.     if (node==0)
  7.     {
  8.         life=-1;
  9.         return 0;
  10.     }
  11.         
  12.     flyengine->hitobj=0;
  13.     if (player>=0)
  14.         flyengine->excludecollision=(bsp_object *)directx->players[player].data;
  15.     particle::step(dt);
  16.     flyengine->excludecollision=0;
  17.  
  18.     if (flyengine->hitobj || life<=0)
  19.         {
  20.         life=-1;
  21.         if (flyengine->hitobj==0)
  22.             if (exp)
  23.                 exp->do_explode(pos,Z,player);
  24.             else ;
  25.         else
  26.             {
  27.             pos=flyengine->hitip+flyengine->hitmesh->faces[flyengine->hitface]->normal;
  28.             if (hm && flyengine->hitmesh->localfaces==0)
  29.                 {
  30.                 hitmark *tmp=(hitmark *)hm->clone();
  31.                 tmp->pos=pos;
  32.                 tmp->mode=0;
  33.                 tmp->align_z(flyengine->hitmesh->faces[flyengine->hitface]->normal);
  34.                 flyengine->activate(tmp);
  35.                 }
  36.             if (exp)
  37.                 exp->do_explode(pos,flyengine->hitmesh->faces[flyengine->hitface]->normal,player);
  38.             }
  39.         }
  40.  
  41.     if (s)
  42.     {
  43.     vector v=pos-startpos;
  44.     float t=v.length();
  45.     if (t-slast>sfact)
  46.         {    
  47.         v/=t;
  48.         int i=(int)(t/sfact);
  49.         int j=(int)(slast/sfact);
  50.         for( ;j<i;j++ )
  51.             {
  52.             sprite_light *tmp=(sprite_light *)s->clone();
  53.             tmp->pos=startpos+v*(sfact*j);
  54.             tmp->align_z(Z);
  55.             flyengine->activate(tmp);
  56.             }
  57.         slast=t;
  58.         }    
  59.     }
  60.  
  61.     if (l)
  62.         {
  63.         l->pos=pos;
  64.         l->step(dt);
  65.         }
  66.  
  67.     force.x=force.y=force.z=0;
  68.  
  69.     return 1;
  70. }
  71.  
  72. void laser::draw()
  73. {
  74.     if (node==0 || flyengine->cam==this) 
  75.         return;
  76.     static vector v;
  77.  
  78.     glDepthMask(GL_FALSE);
  79.     glBlendFunc(GL_ONE,GL_ONE);
  80.     glDisable(GL_CULL_FACE);
  81.     glDisable(GL_FOG);
  82.     glColor4f(1,1,1,1);
  83.  
  84.     if (fronttexture==-1)
  85.         {
  86.         if (sidetexture!=-1)
  87.             {
  88.             tc->use(sidetexture);
  89.             v=pos-flyengine->cam->pos;
  90.             X.cross(v,Z);
  91.             X.normalize();
  92.             glBegin(GL_QUADS);
  93.             glTexCoord2f(1,1);
  94.             glVertex3f(
  95.                 startpos.x-sizetexture*X.x,
  96.                 startpos.y-sizetexture*X.y,
  97.                 startpos.z-sizetexture*X.z);
  98.             glTexCoord2f(0,1);
  99.             glVertex3f(
  100.                 startpos.x+sizetexture*X.x,
  101.                 startpos.y+sizetexture*X.y,
  102.                 startpos.z+sizetexture*X.z);
  103.             glTexCoord2f(0,0);
  104.             glVertex3f(
  105.                 pos.x+sizetexture*X.x,
  106.                 pos.y+sizetexture*X.y,
  107.                 pos.z+sizetexture*X.z);
  108.             glTexCoord2f(1,0);
  109.             glVertex3f(
  110.                 pos.x-sizetexture*X.x,
  111.                 pos.y-sizetexture*X.y,
  112.                 pos.z-sizetexture*X.z);
  113.             glEnd();
  114.             }
  115.         }
  116.     else
  117.         {
  118.         tc->use(fronttexture);
  119.         X=flyengine->cam->X*sizetexture;
  120.         Y=flyengine->cam->Y*sizetexture;
  121.         if (sidetexture!=-1)
  122.             v=Z*sizetexture;
  123.         else v.x=v.y=v.z=0.0f;
  124.         glBegin(GL_QUADS);
  125.         glTexCoord2f(0,0);
  126.         glVertex3f(
  127.             pos.x-Y.x-X.x+v.x,
  128.             pos.y-Y.y-X.y+v.y,
  129.             pos.z-Y.z-X.z+v.z);
  130.         glTexCoord2f(0,1);
  131.         glVertex3f(
  132.             pos.x+Y.x-X.x+v.x,
  133.             pos.y+Y.y-X.y+v.y,
  134.             pos.z+Y.z-X.z+v.z);
  135.         glTexCoord2f(1,1);
  136.         glVertex3f(
  137.             pos.x+Y.x+X.x+v.x,
  138.             pos.y+Y.y+X.y+v.y,
  139.             pos.z+Y.z+X.z+v.z);
  140.         glTexCoord2f(1,0);
  141.         glVertex3f(
  142.             pos.x-Y.x+X.x+v.x,
  143.             pos.y-Y.y+X.y+v.y,
  144.             pos.z-Y.z+X.z+v.z);
  145.         glEnd();
  146.  
  147.         sizetexture*=2.0f;
  148.         if (sidetexture!=-1)
  149.             {
  150.             v=pos-flyengine->cam->pos;
  151.             X.cross(v,Z);
  152.             X.normalize();
  153.             X.x*=0.5f; X.y*=0.5f; X.z*=0.5f;
  154.  
  155.             tc->use(sidetexture);
  156.  
  157.             glBegin(GL_QUADS);
  158.             glTexCoord2f(1,1);
  159.             glVertex3f(
  160.                 pos.x-sizetexture*(Z.x+X.x),
  161.                 pos.y-sizetexture*(Z.y+X.y),
  162.                 pos.z-sizetexture*(Z.z+X.z));
  163.             glTexCoord2f(1,0);
  164.             glVertex3f(
  165.                 pos.x+sizetexture*(Z.x-X.x),
  166.                 pos.y+sizetexture*(Z.y-X.y),
  167.                 pos.z+sizetexture*(Z.z-X.z));
  168.             glTexCoord2f(0,0);
  169.             glVertex3f(
  170.                 pos.x+sizetexture*(Z.x+X.x),
  171.                 pos.y+sizetexture*(Z.y+X.y),
  172.                 pos.z+sizetexture*(Z.z+X.z));
  173.             glTexCoord2f(0,1);
  174.             glVertex3f(
  175.                 pos.x-sizetexture*(Z.x-X.x),
  176.                 pos.y-sizetexture*(Z.y-X.y),
  177.                 pos.z-sizetexture*(Z.z-X.z));
  178.             glEnd();
  179.             }
  180.         sizetexture*=0.5f;
  181.         }
  182.  
  183.     glDepthMask(GL_TRUE);
  184.     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  185.     if (flyengine->fog) glEnable(GL_FOG);
  186.     glEnable(GL_CULL_FACE);
  187.     if (l)
  188.         {
  189.         l->pos=pos;
  190.         l->draw();
  191.         }    
  192. }
  193.  
  194. bsp_object *laser::clone()
  195. {
  196.     laser *tmp=new laser;
  197.     *tmp=*this;
  198.     tmp->source=this;
  199.     return tmp;
  200. }
  201.  
  202. int laser::get_custom_param_desc(int i,param_desc *pd)
  203. {
  204.     if (pd!=0)
  205.     switch(i)
  206.     {
  207.         case 0:
  208.             pd->type='f';
  209.             pd->data=&sizetexture;
  210.             strcpy(pd->name,"sizetexture");
  211.             break;
  212.         case 1:
  213.             pd->type='p';
  214.             pd->data=&fronttexture;
  215.             strcpy(pd->name,"fronttexture");
  216.             break;
  217.         case 2:
  218.             pd->type='p';
  219.             pd->data=&sidetexture;
  220.             strcpy(pd->name,"sidetexture");
  221.             break;
  222.         case 3:
  223.             pd->type=TYPE_EXPLODE;
  224.             pd->data=&exp;
  225.             strcpy(pd->name,"explode");
  226.             break;
  227.         case 4:
  228.             pd->type=TYPE_LIGHT;
  229.             pd->data=&l;
  230.             strcpy(pd->name,"light");
  231.             break;
  232.         case 5:
  233.             pd->type=TYPE_SPRITE_LIGHT;
  234.             pd->data=&s;
  235.             strcpy(pd->name,"sprite");
  236.             break;
  237.         case 6:
  238.             pd->type='f';
  239.             pd->data=&sfact;
  240.             strcpy(pd->name,"spritefactor");
  241.             break;
  242.         case 7:
  243.             pd->type=TYPE_HITMARK;
  244.             pd->data=&hm;
  245.             strcpy(pd->name,"hitmark");
  246.             break;
  247.         case 8:
  248.             pd->type='f';
  249.             pd->data=&damage;
  250.             strcpy(pd->name,"damage");
  251.             break;
  252.     }
  253.     return 9;
  254. }
  255.  
  256. void laser::fire(vector& p,vector& dir,float v,int playerid)
  257. {
  258.     laser *m=(laser *)clone();
  259.     m->startpos=m->pos=p;
  260.     m->vel=dir*v;
  261.     m->align_z(dir);
  262.     m->player=playerid;
  263.     flyengine->activate(m);
  264. }
  265.